package com.onec.service.customer.service.base;


import cn.hutool.core.date.DateUtil;
import com.onec.service.api.dto.response.customer.AgentInfoResp;
import com.onec.service.api.enums.error.AgentErrorEnum;
import com.onec.service.customer.entity.agent.AgentBusiness;
import com.onec.service.customer.entity.agent.AgentInfo;
import com.onec.service.customer.entity.agent.AgentKey;
import com.onec.service.service.AgentInfoService;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * 机构接口返回基类：
 *
 * @author onec
 */
public class BaseAgentInfoServiceImpl implements CustomerService {

    @Autowired
    protected AgentInfoService agentInfoService;

    /**
     * @param agentErrorEnum
     * @return AgentInfoResp
     */
    protected AgentInfoResp respErrorAgentInfo(AgentErrorEnum agentErrorEnum) {
        AgentInfoResp agentInfoResp = new AgentInfoResp();
        agentInfoResp.setCode(agentErrorEnum.getIndex());
        agentInfoResp.setMessage(agentErrorEnum.getMsg());

        return agentInfoResp;
    }

    /**
     * @param agentInfo
     * @param agentKey
     * @return AgentInfoResp
     */
    protected AgentInfoResp respAgentInfo(AgentInfo agentInfo, AgentKey agentKey) {
        AgentInfoResp agentInfoResp = respErrorAgentInfo(AgentErrorEnum.SUCCESS);
        agentInfoResp.setAgentCode(agentInfo.getAgentCode());
        agentInfoResp.setContacts(agentInfo.getContacts());
        agentInfoResp.setCreateTime(DateUtil.formatTime(agentInfo.getCreateTime()));
        agentInfoResp.setUpdateTime(DateUtil.formatDateTime(agentInfo.getUpdateTime()));
        agentInfoResp.setDecryptKey(agentKey.getDecryptKey());
        agentInfoResp.setEncryptKey(agentKey.getEncryptKey());
        agentInfoResp.setExtKey(agentKey.getExtKey());
        agentInfoResp.setSignKey(agentKey.getSignKey());
        agentInfoResp.setExtNo(agentKey.getExtNo());
        agentInfoResp.setName(agentInfo.getName());
        agentInfoResp.setNo(agentInfo.getNo());
        agentInfoResp.setPhone(agentInfo.getPhone());
        return agentInfoResp;
    }

    /**
     * @param agentInfo
     * @param
     * @return AgentInfoResp
     */
    protected AgentInfoResp respAgentBusInfo(AgentInfo agentInfo, AgentBusiness agentBusiness) {
        AgentInfoResp agentInfoResp = respErrorAgentInfo(AgentErrorEnum.SUCCESS);
        agentInfoResp.setAgentCode(agentInfo.getAgentCode());
        agentInfoResp.setCreateTime(DateUtil.formatTime(agentBusiness.getCreateTime()));
        agentInfoResp.setUpdateTime(DateUtil.formatDateTime(agentBusiness.getUpdateTime()));

        agentInfoResp.setName(agentInfo.getName());
        agentInfoResp.setNo(agentInfo.getNo());

        agentInfoResp.setRate(agentBusiness.getRate());
        agentInfoResp.setFee(agentBusiness.getFee());
        agentInfoResp.setBusinessNo(agentBusiness.getBusinessNo());
        return agentInfoResp;
    }
}
